<template>
  <div class="container" style="height: 100%">

    <div class="query-form query-form-2" >
        <el-select v-model="pageObj.type" placeholder="主体类型" style="width: 200px">
          <el-option :value="1" label="部门正职排行"></el-option>
          <el-option :value="2" label="其他排行"></el-option>
        </el-select>
        <el-button @click="loadData">查询</el-button>
        <el-button @click="handleExport">导出</el-button>
    </div>

    <div style="padding:20px;">
      <el-table class="roomTable" :data="tableData">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column label="人员" prop="assesseeName"></el-table-column>
        <el-table-column label="得分" prop="score"></el-table-column>
        <el-table-column label="考核时间" width="280">
          <template slot-scope="{row}">{{row['startDate']}} - {{row['endDate']}}</template>
        </el-table-column>
      </el-table>
    </div>

    <div class="page-div">
      <el-pagination layout="prev, pager, next,jumper,sizes" :current-page="pageObj.page" :page-size="pageObj.pageSize"
                     :total="pageObj.total" @current-change="currentPageChange" @size-change="sizeChange"
                     :page-sizes='pageObj.pageSizes'></el-pagination>
    </div>

  </div>
</template>

<script>

import { listMixin } from '@/mixin'
import { statisticsAssessmentList, exportExcel } from '@/api/assessment'

export default {
  name: 'index',
  mixins: [listMixin],
  data() {
    return {
      pageObj: { page: 1, pageSize: 10, total: 0, type: 1 },
      tableData: [],
    }
  },
  methods: {
    loadData() {
      return statisticsAssessmentList(this.pageObj).then(res => {
        let { data, total } = res
        this.tableData = data
        this.pageObj.total = total
      })
    },
    handleExport(){
      exportExcel().then(res => {
        var blob = new Blob([res])
        let realFileName = "考核排行.xls";
        let url = URL.createObjectURL(new Blob([blob]))
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', realFileName)
        document.body.appendChild(link)
        link.click()
      })
    }
  },
  mounted() {
    this.loadDataProxy();
  }
}
</script>
